$(function(){
    $(".black").on("click",function(){
        ShowTipBox();
        var id=$(this).attr("status");
        $(".a-confirm").on("click",function(){
            ajax("post","/activity/del",{id:id},function success(data){
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function(){
                        location.reload();
                    },1200)
                }else{
                    layer.msg(data.msg)
                }
            },function error(data){
                layer.msg(data.msg)
            })
        });
        $(".a-cancel").on("click",function(){
            location.reload('/activity/activity');
        });
    })
    
    $(".begin").on("click",function(){
        ShowTipBoxBegin();
        var id=$(this).attr("status");
        $(".a-confirm").on("click",function(){
            ajax("post","/activity/begin",{id:id},function success(data){
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function(){
                        location.reload();
                    },1200)
                }else{
                    layer.msg(data.msg)
                }
            },function error(data){
                layer.msg(data.msg)
            })
        });
        $(".a-cancel").on("click",function(){
            location.reload('/activity/activity');
        });
    })
    
    $(".end").on("click",function(){
        ShowTipBoxEnd();
        var id=$(this).attr("status");
        $(".a-confirm").on("click",function(){
            ajax("post","/shop/end",{id:id},function success(data){
                if(data.code==200){
                    layer.msg(data.msg);
                    setTimeout(function(){
                        location.reload();
                    },1200)
                }else{
                    layer.msg(data.msg)
                }
            },function error(data){
                layer.msg(data.msg)
            })
        });
        $(".a-cancel").on("click",function(){
            location.reload('/activity/activity');
        });
    })

    // 二维码
    $(".code").on("click",function(){
        var id=$(this).attr("status");
        ajax("post","/activity/attrcode",{id:id},function success(data){
            console.log(data);
            if(data.code==200){
                ShowTransportNoBox(data.data.cdnUrl);
            }else{
                layer.msg(data.msg)
            }
        },function error(data){
            layer.msg(data.msg)
        })
    })
})
function ShowTransportNoBox(src){
    var dIv=$("<div class='b-div'><h4 class='b-h4'>提示</h4><p class='b-p'>已生成二维码</p><div><img src='"+src+"'/></div><div class='b-btn'><input type='button' value='确认' class='b-confirm btn-primary'><input type='button' value='取消' class='b-cancel'></div></div>");
    $("body").append(dIv);
    $(".b-confirm").on("click",function(){
        location.reload('/activity/activity');
    })
    $(".b-cancel").on("click",function(){
        location.reload('/activity/activity');
    })
};
